﻿using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.Configuration;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Threading.Tasks;
using Truron.Purchase.Model.RemoteModel;
using Truron.Purchase.Utility.RedisHelper;

namespace Truron.Purchase.Api.Utility
{
    public class FinanceServiceHelp
    {
        private static string FinanceApiUrl = "";//系统服务调用地址
        public readonly static FinanceServiceHelp Instance = new FinanceServiceHelp();
        public FinanceServiceHelp()
        {
            var Configuration = new ConfigurationBuilder()
                  .SetBasePath(Directory.GetCurrentDirectory())
                  .AddJsonFile("appsettings.json", optional: true)
                  .Build();
            FinanceApiUrl = Configuration.GetSection("AppSettings:FinanceApiUrl").Value;

        }

        public (int code, List<FinancePaymentModel> list) GetPayListByIds(UserCache userToken, List<int> Ids)
        {
            Dictionary<string, object> postData = new Dictionary<string, object>();
            postData.Add("Ids", Ids);
            var dataobj = ApiHelp.WebPost(FinanceApiUrl + "Finance_Payment/GetListByIds", userToken.UserToken, postData);
            if (dataobj.code > 0)
                return (dataobj.code, null);
            return (dataobj.code, JsonConvert.DeserializeObject<List<FinancePaymentModel>>(dataobj.data.ToString()));
        }

        public (int code, List<FinanceInvoiceModel> list) GetInvoiceListByIds(UserCache userToken, List<int> Ids)
        {
            Dictionary<string, object> postData = new Dictionary<string, object>();
            postData.Add("Ids", Ids);
            var dataobj = ApiHelp.WebPost(FinanceApiUrl + "Finance_PayInvoice/GetListByIds", userToken.UserToken, postData);
            if (dataobj.code > 0)
                return (dataobj.code, null);
            return (dataobj.code, JsonConvert.DeserializeObject<List<FinanceInvoiceModel>>(dataobj.data.ToString()));
        }
    }
}
